<template>
    <div class="production-plan">
        <h3 class="title">生产废料</h3>
    
    <!-- 基本信息 -->

 <el-form ref="formRef" :model="formData" :rules="rules" label-position="right" label-width="80px">
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form-item label="单据主题">
            <el-input v-model="formData.documentSubject" placeholder="请输入主题" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="单据编号">
            <el-input v-model="formData.documentNumber" placeholder="请输入编号" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="7">
          <el-form-item label="废料日期" prop="wasteDate" class="bordered-form-item">
            <el-date-picker
              v-model="formData.wasteDate"
              type="date"
              required
              disabled
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="6">
            <el-form-item label="是否需要入库" prop="needStorage" required>
                <el-radio-group v-model="formData.needStorage" disabled>
                <el-radio :label="true">是</el-radio>
                <el-radio :label="false">否</el-radio>
                </el-radio-group>
            </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="制单人员" prop="documentMaker" required>
            <el-input v-model="formData.documentMaker" placeholder="系统自动生成"  disabled />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="备注">
            <el-input v-model="formData.remarks"  disabled />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    </div>
</template>

<script setup>
import { ref, reactive, onMounted, watch } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus';
import { useRouter, useRoute } from 'vue-router';
import { read, write } from '@/axios/axiosHelper';
import axios from 'axios';
import { Materialread, Materialwrite } from '@/axios/axiosHelper';
const formRef = ref(null);
const currentUser = ref("admin");
const router = useRouter();
const route = useRoute();

// 主表单数据，使用驼峰命名规范，使变量命名更统一
// 主表单数据
const formData = reactive({
  productionWasteZID: route.query.productionWasteZID,
  documentSubject: "",
  documentNumber:"" ,
  wasteDate: new Date().toISOString(), // 默认为当前日期
  needStorage: true,
  documentMaker:  currentUser.value,
  remarks: "",
});

const getProductionById = (productionWasteZID) => {
  console.log('查看反填数据:', productionWasteZID);
  axios.get('https://localhost:7278/api/ProductionWasteZ/FTProductionWasteZ', {
      params:{
        ProductionWasteZID: route.query.productionWasteZID
      }
    })
    .then(res=>{
      formData.productionWasteZID = res.data.data[0].ProductionWasteZID;
      formData.documentSubject = res.data.data[0].documentSubject;
      formData.documentNumber = res.data.data[0].documentNumber;
      formData.wasteDate = res.data.data[0].wasteDate;
      formData.needStorage = res.data.data[0].needStorage;
      formData.documentMaker = res.data.data[0].documentMaker;
      formData.remarks = res.data.data[0].remarks;
      formData.modelValue = res.data.data[0];
      console.log('反填数据:', res.data);
    })
};
const saveAll = () => {
    // 这里可以添加保存主表单和明细的逻辑
    ElMessage.warning('保存功能待实现');
};

onMounted(() => {
    getProductionById();
});
</script>

<style scoped>
.production-plan {
    padding: 20px;
}

.title {
    text-align: center;
    margin-bottom: 20px;
}

.sub-title {
    margin: 20px 0 10px;
    font-size: 16px;
    font-weight: 500;
}

.detail-section,
.attachment-section {
    margin-top: 20px;
}

.el-table {
    margin-top: 10px;
}
</style>